package com.zhumei.keyscale.server;

import android.util.*;
import android.content.*;
import com.blankj.utilcode.util.*;
import com.zhumei.keyscale.receiver.*;
import android.app.*;
import android.os.*;

public class KeepAliveService extends Service
{
    private boolean mIsEffective;
    
    public KeepAliveService() {
        this.mIsEffective = false;
    }
    
    public IBinder onBind(final Intent intent) {
        return null;
    }
    
    public void onCreate() {
        super.onCreate();
    }
    
    public void onDestroy() {
        super.onDestroy();
        Log.e("TAG", "onDestroy: \u5173\u95ed\u4e86service");
        this.startService(new Intent((Context)this, (Class)KeepAliveService.class));
    }
    
    public int onStartCommand(final Intent intent, final int n, final int n2) {
        if (AppUtils.isAppForeground()) {
            LogUtils.e("the application runs in the foreground!");
            this.mIsEffective = true;
        }
        else if (this.mIsEffective) {
            LogUtils.e("the application runs in the background, need to return to foreground!");
            final String packageName = this.getPackageName();
            if (AppUtils.isAppInstalled(packageName)) {
                AppUtils.launchApp(packageName);
            }
        }
        else {
            LogUtils.e("the application runs in the background, two minutes later return to foreground!");
            this.mIsEffective = true;
        }
        final AlarmManager alarmManager = (AlarmManager)this.getSystemService("alarm");
        final Intent intent2 = new Intent((Context)this, (Class)KeepAliveReceiver.class);
        intent2.setAction("zhumei.intent.action.KEEP_ALIVE");
        final PendingIntent broadcast = PendingIntent.getBroadcast((Context)this, 0, intent2, 1073741824);
        if (alarmManager != null) {
            alarmManager.set(2, SystemClock.elapsedRealtime() + 120000L, broadcast);
        }
        return super.onStartCommand(intent2, n, n2);
    }
}
